const getUrlParams = (url) => {
  // TODO：待补充代码 目标 2
  const index = url.indexOf("?");
  if (index != -1) {
    let str = "";
    for (let i = index + 1; i < url.length; i++) str += url[i];
    console.log(str);
    str = JSON.parse(`{"` + str.replaceAll("=",`":"`).replaceAll("&",`","`) + `"}`);
    return str;
  } else return null;
  // TODO：END
};

window.getUrlParams = getUrlParams;

// 目标 2 测试用例
console.log(getUrlParams(`http://127.0.0.1:5501/index.html?page=1`));
// 输出结果为：{page: '1'}
console.log(getUrlParams(`http://example.com?id=2&name=tom`));
// 输入结果为：{id: '2', name: 'tom'}
